﻿namespace AutoBackupDatabase.Form
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Drawing;
    using System.Drawing.Printing;
    using System.Linq;
    using System.Windows.Forms;

    using DevExpress.Utils;
    using DevExpress.XtraGrid.Columns;

    using General;

    using AutoBackupDatabase.BLL;
    using AutoBackupDatabase.ENT;

    using DevExpress.XtraEditors;

    public partial class frmControl : DevExpress.XtraEditors.XtraForm
    {

        private AREABLL areaBll;

        private TABLEBLL tableBll;

        private ITEMBLL itemBLL;

        private EXPORTENT expENT;

        public EXPORTBLL expBLL;

        private DETAILGROUPUSERROLEBLL checkRole;

        public frmControl()
        {
            InitializeComponent();
            areaBll = new AREABLL();
            areaBll.GetAllareaData();
            tableBll = new TABLEBLL();
            itemBLL = new ITEMBLL();
            expBLL = new EXPORTBLL();
            checkRole = new DETAILGROUPUSERROLEBLL();

        }

        private Label label2;

        private int flat = 0;

        private int labelHeight = 0;

        private int labelWidth = 0;

        private int btnX = 5;

        private int btnY = 10;

        private SimpleButton button1;

        private EXPORTDETAILENT item;

        private DataRow row;

        private void frmControl_Load(object sender, EventArgs e)
        {
            this.BuildTablePanel();
            var data = this.itemBLL.GET_ITEM_ALL();
            this.gridControl1.DataSource = data;
            glkItem.DataSource = data;

        }

        public void BuildTablePanel()
        {
            btnX = 5;
            flat = 0;
            btnY = 10;
            this.panelTable.Controls.Clear();
            var area = this.areaBll.GetAllareaData();
            var table = this.tableBll.GET_TABLE_ALL();
            for (int i = 0; i < area.Count; i++)
            {
                if (table.Any(x => x.AREAID == area[i].AREAID))
                {
                    //add label 
                    if (this.btnY > 55)
                    {
                        this.btnY += 55;
                        this.btnX = 5;
                        this.flat = 0;
                    }
                    this.label2 = new Label();
                    this.label2.Location = new System.Drawing.Point(this.btnX, this.btnY);
                    this.label2.Name = area[i].AREAID;
                    this.label2.Size = new System.Drawing.Size(35, 13);
                    this.label2.TabIndex = 0;
                    this.label2.Text = area[i].AREANAME;
                    this.label2.AutoSize = true;
                    this.label2.Font = new System.Drawing.Font(
                        "Tahoma", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

                    this.btnY += this.label2.Height + 25;
                    this.panelTable.Controls.Add(this.label2);
                    for (int j = 0; j < table.Count; j++)
                    {
                        if (table[j].AREAID == area[i].AREAID)
                        {
                            if (this.flat == 0)
                            {

                                this.button1 = new SimpleButton();
                                if (expBLL.ISTABLEHAVEGUEST(table[j].TABLEID) > 0)
                                {
                                    this.button1.Appearance.ForeColor = Color.White;
                                    this.button1.Appearance.BackColor = System.Drawing.Color.DodgerBlue;


                                }
                                else
                                {
                                    this.button1.Appearance.BackColor = System.Drawing.Color.Wheat;
                                }
                                this.button1.ButtonStyle = DevExpress.XtraEditors.Controls.BorderStyles.Style3D;
                                this.button1.Appearance.Options.UseBackColor = true;

                                this.button1.Appearance.Font = new System.Drawing.Font(
                                    "Tahoma",
                                    18F,
                                    System.Drawing.FontStyle.Bold,
                                    System.Drawing.GraphicsUnit.Point,
                                    ((byte)(0)));
                                this.button1.Appearance.Options.UseFont = true;
                                this.button1.Location = new System.Drawing.Point(this.btnX, this.btnY);
                                this.button1.Name = table[j].TABLEID.ToString();
                                this.button1.Size = new System.Drawing.Size(75, 50);
                                this.button1.TabIndex = 1;
                                this.button1.Click += button1_Click;
                                this.button1.Text = table[j].TABLENAME;
                                this.panelTable.Controls.Add(this.button1);

                                this.flat = 1;
                                this.btnX += this.button1.Width + 5;
                                
                            }

                            else if (this.flat == 1)
                            {
                                this.button1 = new SimpleButton();
                                if (expBLL.ISTABLEHAVEGUEST(table[j].TABLEID) > 0)
                                {
                                    this.button1.Appearance.ForeColor = Color.White;
                                    this.button1.Appearance.BackColor = System.Drawing.Color.DodgerBlue;

                                }
                                else
                                {
                                    this.button1.Appearance.BackColor = System.Drawing.Color.Wheat;
                                }
                                this.button1.Appearance.Options.UseBackColor = true;
                                this.button1.ButtonStyle = DevExpress.XtraEditors.Controls.BorderStyles.Style3D;

                                this.button1.Appearance.Font = new System.Drawing.Font(
                                    "Tahoma",
                                    18F,
                                    System.Drawing.FontStyle.Bold,
                                    System.Drawing.GraphicsUnit.Point,
                                    ((byte)(0)));
                                this.button1.Appearance.Options.UseFont = true;
                                this.button1.Location = new System.Drawing.Point(this.btnX, this.btnY);
                                this.button1.Name = table[j].TABLEID.ToString();
                                this.button1.Size = new System.Drawing.Size(75, 50);
                                this.button1.TabIndex = 1;
                                this.button1.Text = table[j].TABLENAME;
                                this.button1.Click += button1_Click;
                                this.panelTable.Controls.Add(this.button1);
                                this.flat = 2;
                                this.btnX += this.button1.Width + 5;
                                
                            }

                            else if (this.flat == 2)
                            {
                                this.button1 = new SimpleButton();
                                if (expBLL.ISTABLEHAVEGUEST(table[j].TABLEID) > 0)
                                {
                                    this.button1.Appearance.ForeColor = Color.White;
                                    this.button1.Appearance.BackColor = System.Drawing.Color.DodgerBlue;

                                }
                                else
                                {
                                    this.button1.Appearance.BackColor = System.Drawing.Color.Wheat;
                                }
                                this.button1.Appearance.Options.UseBackColor = true;
                                this.button1.ButtonStyle = DevExpress.XtraEditors.Controls.BorderStyles.Style3D;
                                this.button1.Appearance.Font = new System.Drawing.Font(
                                    "Tahoma",
                                    18F,
                                    System.Drawing.FontStyle.Bold,
                                    System.Drawing.GraphicsUnit.Point,
                                    ((byte)(0)));
                                this.button1.Appearance.Options.UseFont = true;
                                this.button1.Location = new System.Drawing.Point(this.btnX, this.btnY);
                                this.button1.Name = table[j].TABLEID.ToString();
                                this.button1.Size = new System.Drawing.Size(75, 50);
                                this.button1.TabIndex = 1;
                                this.button1.Text = table[j].TABLENAME;
                                this.button1.Click += button1_Click;
                                this.panelTable.Controls.Add(this.button1);

                                this.btnY += this.button1.Height + 5;
                                this.btnX = 5;
                                this.flat = 0;
                            }
                        }
                    }
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {

            var button = ((SimpleButton)sender);
            button.Appearance.BackColor = System.Drawing.Color.DarkRed;
            button.Appearance.ForeColor = Color.White;

            general.TableId = int.Parse(button.Name);
            lbTable.Text = "BÀN " + general.TableId;
            button.LostFocus += this.button_LostFocus;
            this.LoadDataGridDetail();
            gridView2.FocusedRowHandle = gridView2.RowCount - 1;
            gridView2.Focus();
        }

        private void LoadDataGridDetail()
        {
            try
            {
                EXPORTDETAILBLL bll = new EXPORTDETAILBLL();

                var listExp = bll.GETDETAILEXPORTBYTABLEID(general.TableId);
                
                this.BuildGridTotal(listExp);
                if (gridView2.RowCount > 0)
                {
                    gridView2.FocusedRowHandle = gridView2.RowCount - 1;
                    gridView2.Focus();
                    txtShortcut.SelectAll();
                    txtShortcut.Focus();
                }
              
            }
            catch (Exception)
            {

                return;
            }
           
        }

       

        private void BuildGridTotal(List<EXPORTDETAILENT> listExp)
        {

            double? totalDicount = 0;
            double? totalService = 0;
            double? totalVAT = 0;

            if (listExp != null && listExp.Count > 0)
            {
                double? total = 0;
                foreach (var itement in listExp)
                {
                    total += itement.TOTAL;
                }

                // empty row
                item = new EXPORTDETAILENT();
                item.QUANTITY = null;
                item.PRICE = null;
                item.ITEMDISCOUNT = null;
                item.TOTAL = null;
                listExp.Add(item);

                // total row
                item = new EXPORTDETAILENT();
                item.TOTAL = total;
                item.ITEMNAME = "Tổng cộng";
                listExp.Add(item);

                // total row
                item = new EXPORTDETAILENT();
                item.TOTAL = -((total * ((EXPORTDETAILENT)listExp[0]).TABLEDISCOUNT) / 100);
                item.ITEMDISCOUNT = listExp[0].TABLEDISCOUNT;
                item.ITEMNAME = "Giảm giá";
                listExp.Add(item);

                // thanh tien
                totalDicount = total - (total * ((EXPORTDETAILENT)listExp[0]).TABLEDISCOUNT) / 100;
                item = new EXPORTDETAILENT();
                item.TOTAL = totalDicount;
                item.ITEMDISCOUNT = null;
                item.ITEMNAME = "Thành tiền";
                listExp.Add(item);

                // service
                item = new EXPORTDETAILENT();
                item.TOTAL = (total * ((EXPORTDETAILENT)listExp[0]).SERVICE) / 100;
                item.ITEMDISCOUNT = listExp[0].SERVICE;
                item.ITEMNAME = "Phí phòng lạnh";
                listExp.Add(item);


                // thanh tien
                totalService = (totalDicount + (total * ((EXPORTDETAILENT)listExp[0]).SERVICE) / 100);
                item = new EXPORTDETAILENT();
                item.TOTAL = totalService;
                item.ITEMDISCOUNT = null;
                item.ITEMNAME = "Thành tiền";
                listExp.Add(item);

                // VAT
                item = new EXPORTDETAILENT();
                item.TOTAL = (total * ((EXPORTDETAILENT)listExp[0]).VAT) / 100;
                item.ITEMDISCOUNT = listExp[0].VAT;
                item.ITEMNAME = "VAT";
                listExp.Add(item);

                // thanh tien thanh toan
                totalVAT = (total + (total * ((EXPORTDETAILENT)listExp[0]).SERVICE) / 100
                            + (total * ((EXPORTDETAILENT)listExp[0]).VAT) / 100)
                           - (total * ((EXPORTDETAILENT)listExp[0]).TABLEDISCOUNT) / 100;
                item = new EXPORTDETAILENT();
                item.TOTAL = totalVAT;
                item.ITEMDISCOUNT = null;
                item.ITEMNAME = "Tiền thanh toán";
                listExp.Add(item);


                txtVat.Text = listExp[0].VAT.ToString();
                txtService.Text = listExp[0].SERVICE.ToString();
                txtDiscount.Text = listExp[0].TABLEDISCOUNT.ToString();
                General.general.EXPORTID = listExp[0].EXPORTID;
                gridControl2.DataSource = listExp;
                gridView2.SelectRow(gridView2.RowCount);


                try
                {
                    if (listExp.Any())
                    {
                        general.EXPORTID = listExp[0].EXPORTID;

                        var result = expBLL.GETEXPORTBYEXPORTID(general.EXPORTID);
                        general.DateCreate = result.DATECREATE;
                        general.DatePaid = result.DATEPAID;
                        general.tableName = result.TABLENAME;
                        general.areaName = result.AREANAME;
                    }
                }
                catch (Exception)
                {

                    return;
                }

                return;
            }
            txtVat.Text = "0";
            txtService.Text = "0";
            txtDiscount.Text = "0";
            gridControl2.DataSource = listExp;

          


        }

        private void button_LostFocus(object sender, EventArgs e)
        {
            var button = ((SimpleButton)sender);

            if (expBLL.ISTABLEHAVEGUEST(int.Parse(button.Name)) > 0)
            {
                button.Appearance.BackColor = System.Drawing.Color.DodgerBlue;
            }
            else
            {
                button.Appearance.BackColor = System.Drawing.Color.Wheat;
                button.Appearance.ForeColor = Color.Black;

            }



        }


        #region Text box Select All

        private void txtDiscount_Click(object sender, EventArgs e)
        {
            txtDiscount.SelectAll();
        }

        private void txtService_Click(object sender, EventArgs e)
        {
            txtService.SelectAll();
        }

        private void txtVat_Click(object sender, EventArgs e)
        {
            txtVat.SelectAll();
        }

        #endregion

        private void btnSaveDiscount_Click(object sender, EventArgs e)
        {
            this.UpdateDiscount();
        }

        private void UpdateDiscount()
        {
            this.expBLL = new EXPORTBLL();
            this.expENT = new EXPORTENT();
            this.expENT.EXPORTID = General.general.EXPORTID;

            this.expENT.SERVICE = float.Parse((this.txtService.Text == "" ?"0" : this.txtService.Text));
            this.expENT.VAT = float.Parse((this.txtVat.Text == "" ? "0" : this.txtVat.Text));
            this.expENT.TABLEDISCOUNT = float.Parse((this.txtDiscount.Text == "" ? "0" : this.txtDiscount.Text));
            if (this.expBLL.UPDATEVATSERVICEDISCOUNT(this.expENT))
            {
                this.LoadDataGridDetail();
            }
        }

        private void gridControl1_MouseDoubleClick(object sender, MouseEventArgs e)
        {

        }

        private void txtDiscount_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (decimal)Keys.Enter)
            {
                this.UpdateDiscount();
            }
        }

        private void gridView1_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                ITEMENT row = (ITEMENT)this.gridView1.GetFocusedRow();
                if ((e as DXMouseEventArgs).Button == System.Windows.Forms.MouseButtons.Left
                    && (e as DXMouseEventArgs).Clicks == 2)
                {

                    // check table is having guest
                    if (expBLL.ISTABLEHAVEGUEST(general.TableId) == general.TableId)
                    {
                        expBLL.ADDITEMTOTABLE(general.EXPORTID, row.ITEMID, 1);
                        this.LoadDataGridDetail();
                        return;
                    }
                    else
                    {
                        expBLL.ADDITEMTOTABLE(expBLL.GETNUMBEROFEXPORT(general.TableId, general.empId), row.ITEMID, 1);
                        this.LoadDataGridDetail();
                        var button = (SimpleButton)this.panelTable.Controls.Find(general.TableId.ToString(), true)[0];
                        button.Appearance.BackColor = System.Drawing.Color.DodgerBlue;

                        return;
                    }
                }

                if ((e as DXMouseEventArgs).Button == System.Windows.Forms.MouseButtons.Right
                    && (e as DXMouseEventArgs).Clicks == 2)
                {

                    if (expBLL.ADDITEMTOTABLE(general.EXPORTID, row.ITEMID, -1))
                    {
                        var button = (SimpleButton)this.panelTable.Controls.Find(general.TableId.ToString(), true)[0];
                        button.Appearance.BackColor = System.Drawing.Color.Wheat;
                        button.Appearance.ForeColor = Color.Black;
                    }
                    this.LoadDataGridDetail();

                    return;
                }

            }
            catch (Exception)
            {

                return;
            }
            
        }


        private void gridView2_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                EXPORTDETAILENT row = (EXPORTDETAILENT)this.gridView2.GetFocusedRow();
                if ((e as DXMouseEventArgs).Button == System.Windows.Forms.MouseButtons.Left
                    && (e as DXMouseEventArgs).Clicks == 2)
                {

                    // check table is having guest
                    if (expBLL.ISTABLEHAVEGUEST(general.TableId) == general.TableId)
                    {
                        expBLL.ADDITEMTOTABLE(general.EXPORTID, row.ITEMID, 1);
                        this.LoadDataGridDetail();
                        return;
                    }
                    else
                    {
                        expBLL.ADDITEMTOTABLE(expBLL.GETNUMBEROFEXPORT(general.TableId, general.empId), row.ITEMID, 1);
                        this.LoadDataGridDetail();
                        var button = (SimpleButton)this.panelTable.Controls.Find(general.TableId.ToString(), true)[0];
                        button.Appearance.BackColor = System.Drawing.Color.DodgerBlue;
                       
                        return;
                    }
                }

                if ((e as DXMouseEventArgs).Button == System.Windows.Forms.MouseButtons.Right
                    && (e as DXMouseEventArgs).Clicks == 2)
                {

                    if (expBLL.ADDITEMTOTABLE(general.EXPORTID, row.ITEMID, -1))
                    {
                        var button = (SimpleButton)this.panelTable.Controls.Find(general.TableId.ToString(), true)[0];
                        button.Appearance.BackColor = System.Drawing.Color.Wheat;
                        button.Appearance.ForeColor = Color.Black;
                    }
                    this.LoadDataGridDetail();
             
                    return;
                }
               
            }
            catch (Exception)
            {

                return;
            }
            
        }

        private void gridView2_PopupMenuShowing(
            object sender, DevExpress.XtraGrid.Views.Grid.PopupMenuShowingEventArgs e)
        {

            //GridView view = sender as GridView;
            //// Check whether a row is right-clicked.
            //if (e.MenuType == DevExpress.XtraGrid.Views.Grid.GridMenuType.Row)
            //{
            //    int rowHandle = e.HitInfo.RowHandle;
            //    // Delete existing menu items, if any.
            //    e.Menu.Items.Clear();
              
            //    // Add a check menu item.
            //    DXMenuItem item = CreateMergingEnabledMenuItem(view, rowHandle);
                
            //    item.BeginGroup = true;
            //    e.Menu.Items.Add(item);
            //}
        }

        //DXMenuCheckItem CreateMergingEnabledMenuItem(GridView view, int rowHandle)
        //{
        //    var checkItem = new DXMenuCheckItem(
        //        "Giảm giá cho món này", view.OptionsView.AllowCellMerge, null, new EventHandler(OnDiscountClicks));
        //    checkItem.Tag = new RowInfo(view, rowHandle);
        //    return checkItem;
        //}

        //void OnDiscountClicks(object sender, EventArgs e)
        //{
        //    EXPORTDETAILENT row = (EXPORTDETAILENT)this.gridView2.GetFocusedRow();
        //    if (row.ITEMID>0)
        //    {
        //        general.itemId = row.ITEMID;
        //        frmDiscountPopup discount=new frmDiscountPopup();
        //        discount.ShowDialog();
        //        this.LoadDataGridDetail();
        //    }
        //}
        //class RowInfo
        //{
        //    public RowInfo(GridView view, int rowHandle)
        //    {
        //        this.RowHandle = rowHandle;
        //        this.View = view;
        //    }
        //    public GridView View;
        //    public int RowHandle;
        //}

     

        private void gridView2_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            EXPORTDETAILENT row = (EXPORTDETAILENT)this.gridView2.GetFocusedRow();
            double? inSt = row.ITEMDISCOUNT;
            string cellValue = "0";
            if (inSt < 0 || inSt > 100)
            {
                //Set errors with specific descriptions for the columns
                MessageBox.Show("Chỉ được giảm giá từ 0% đến 100%", "Thông báo");
               this.LoadDataGridDetail();
                return;
            }
            try
            {
                EXPORTDETAILBLL bll = new EXPORTDETAILBLL();
                bll.UPDATEDISCOUNTFORITEM(General.general.EXPORTID, row.ITEMID, (float)inSt);
                this.LoadDataGridDetail();
                gridView2.FocusedRowHandle = gridView2.RowCount - 1;
                gridView2.Focus();
            }
            catch (Exception)
            {
                return;
            }

        }

        private void gridView2_Click(object sender, EventArgs e)
        {
            try
            {
                EXPORTDETAILENT row = (EXPORTDETAILENT)this.gridView2.GetFocusedRow();
                general.itemId = row.ITEMID;
              
            }
            catch (Exception)
            {
                
                return;
            }

        }
    
        private void btnExport_Click(object sender, EventArgs e)
        {
            try
            {
                if (gridView2.RowCount > 0)
                {


                    if (MessageBox.Show("Bạn có muốn in hóa đơn ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {

                        printDocument1.PrinterSettings.PrinterName = general.PrinterBillName;
                        printDocument1.Print();
                    }
                    general.DatePaid = DateTime.Now;
                    expBLL.PAIDBILL(general.EXPORTID, general.DatePaid);
                    var button = (SimpleButton)this.panelTable.Controls.Find(general.TableId.ToString(), true)[0];
                    button.Appearance.BackColor = System.Drawing.Color.Wheat;
                    button.Appearance.ForeColor = Color.Black;
                }
            
            }
            catch (Exception)
            {

                MessageBox.Show("Không tìm thấy máy in vui lòng kiểm tra lại phần cài đặt", "Thông báo");
                return;
            }
            

        }

        

        int x = 0;
        int y = 0;
        private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
        {
            x = 0;
            y = 0;
            var font = new Font("Tahoma", 14);
            //draw title
            if (general.isTitlePrint)
            {
               
                   e.Graphics.DrawString(general.titlePrint, font, Brushes.Black, new RectangleF(15, y, 210, 20));
                
            }
         
            // draw Name of bussiness
            if (general.isLogoTextPrint)
            {
                font = new Font("Tahoma", 38,FontStyle.Bold);
                y += 20;
                e.Graphics.DrawString("SOKUL", font, Brushes.Black, new RectangleF(0, y, 220, 95));
                y += 75;

            }
            
            //drawing logo
            Image i = Image.FromFile(general.GetStartupPath() + @"\img\logo.png");
            if (general.isLogoImagePrint)
            {
                y += 20;
                 
            Point p = new Point(0, y);
            e.Graphics.DrawImage(i, 0, y, i.Width+10, i.Height);
                y += i.Height;
            }

           

            // drawing date
            font = new Font("Tahoma", 7);
            if (general.isDatePrint)
            {
               
                    
            e.Graphics.DrawString(string.Format("{0:dd/MM/yyyy}",general.DateCreate), font, Brushes.Black, new RectangleF(65,y, 100, 15));
                y += 15;
            }

            // time in
            if (general.isTimeInPrint)
            {
                
                e.Graphics.DrawString(string.Format("{0:hh:mm tt}", general.DateCreate), font, Brushes.Black, new RectangleF(0, y, 110, 15));
             
            }

            // timeout
            if (general.isTimeOutPrint)
            {

                e.Graphics.DrawString(string.Format("{0:hh:mm tt}", general.DatePaid), font, Brushes.Black, new RectangleF(125, y, 100, 15));
                y += 15;
            }

            //draw table
            if (general.isTablePrint)
            {
             
            e.Graphics.DrawString("Bàn "+general.tableName +"("+general.areaName+")", font, Brushes.Black, new RectangleF(0, y, 130, 15));
         

            }
            //draw exportid
            if (general.isExportIdPrint)
            {
              
                e.Graphics.DrawString(general.EXPORTID, font, Brushes.Black, new RectangleF(125, y, 90, 15));
                y += 15;

            }

            
            // draw custumername

            if (general.isCustomerPrint && txtNote.Text!="")
            {
                
                e.Graphics.DrawString("Ghi chú : "+txtNote.Text, font, Brushes.Black, new RectangleF(0, y, 220, 15));
                y += 15;

            }

            // draw title of grid
            font = new Font("Tahoma", 10);
            y += 20;
            e.Graphics.DrawString("Tên Món", font, Brushes.Black, new RectangleF(0, y, 110, 20));
            e.Graphics.DrawString("SL", font, Brushes.Black, new RectangleF(120, y, 125, 20));
            e.Graphics.DrawString("ĐGiá", font, Brushes.Black, new RectangleF(150, y, 125, 20));
            y += 10;
            e.Graphics.DrawString("--------------------------------------------", font, Brushes.Black, new RectangleF(0, y, 250, 20));

            y += 15;
            //draw item
            var entList = gridView2.DataSource as List<EXPORTDETAILENT>;
            font = new Font("Tahoma", 7);
            foreach (var item in entList)
            {
                if (item.ITEMNAME==""||item.ITEMNAME==null)
                {
                    e.Graphics.DrawString("--------------------", font, Brushes.Black, new RectangleF(120, y - 5, 125, 15));
                    y += 5;
                    break;
                }
                e.Graphics.DrawString(item.ITEMNAME, font, Brushes.Black, new RectangleF(0, y, 110, 15));
                e.Graphics.DrawString(item.QUANTITY.ToString(), font, Brushes.Black, new RectangleF(120, y, 125, 15));
                e.Graphics.DrawString(string.Format("{0:0,0}",item.PRICE), font, Brushes.Black, new RectangleF(150, y, 125, 15));
                y += 15;

            }
            // draw total
            double? total=0;
            double? totalPaid = 0;

            if (general.isTotalPrint)
            {
                foreach (var item in entList)
                {
                    if (item.ITEMNAME == "Tổng cộng")
                    {
                        e.Graphics.DrawString(item.ITEMNAME, font, Brushes.Black, new RectangleF(0, y, 110, 15));
                        e.Graphics.DrawString(string.Format("{0:0,0}", item.TOTAL), font, Brushes.Black, new RectangleF(140, y, 125, 15));
                        total = item.TOTAL;
                        totalPaid = item.TOTAL;
                        y += 15;
                        break;
                    }


                }
            }
            

            // draw discount
            if (general.isTotalDiscount)
            {
                foreach (var item in entList)
                {
                    if (item.ITEMNAME == "Tiền thanh toán")
                    {
                        e.Graphics.DrawString(string.Format("-{0:0,0}", (total - item.TOTAL)), font, Brushes.Black, new RectangleF(140, y, 125, 15));
                        totalPaid = (total - item.TOTAL) == 0 ? item.TOTAL : item.TOTAL;
                        y += 15;
                        break;
                    }


                }
            }
            

            //draw total pay
            if (general.isTotalPayPrint)
            {
                e.Graphics.DrawString("---------------------------------------------------------", font, Brushes.Black, new RectangleF(0, y - 5, 250, 10));
                y += 10;

                font = new Font("Tahoma", 8);
                e.Graphics.DrawString("Tiền thanh toán", font, Brushes.Black, new RectangleF(0, y, 110, 30));
                e.Graphics.DrawString(string.Format("{0:0,0} d", totalPaid), font, Brushes.Black, new RectangleF(120, y, 250, 30));
                y += 15;
            }


            if (general.isSayGoodByePrint)
            {
                y += 30;
                e.Graphics.DrawString(general.isSayGoodByeText1, font, Brushes.Black, new RectangleF(50, y, 250, 15));
                y += 15;
                e.Graphics.DrawString(general.isSayGoodByeText2, font, Brushes.Black, new RectangleF(65, y, 250, 250));
                y += 15;

            }

            if (general.isDiscountInfomationPrint)
            {
                y += 30;
                e.Graphics.DrawString(general.DiscountInfomationPrintTest, font, Brushes.Black, new RectangleF(0, y, 210, 1500));
               

            }

            // draw emply space
            
            y += 10;
            e.Graphics.DrawString(string.Format("\n{0}","."), font, Brushes.LightGreen, new RectangleF(0, y, 120, 250));
        }
        #region Menu  Code

        private void khuVựcToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            try
            {

                if (checkRole.CHECKROLE(general.groupUserCode, Role.area_read))
                {
                    if (Application.OpenForms["frmArea"] == null)
                    {
                        frmArea area = new frmArea();
                        area.ShowDialog();
                        return;

                    }
                    Application.OpenForms["frmArea"].ShowDialog();
                    return;
                }
                MessageBox.Show("Bạn chưa chưa được cấp quyền sử dụng cho tính năng này");
            }
            catch (Exception)
            {


            }
           
        }

        private void bànToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {

                if (checkRole.CHECKROLE(general.groupUserCode, Role.table_read))
                {
                    if (Application.OpenForms["frmTable"] == null)
                    {
                        frmTable area = new frmTable();
                        area.ShowDialog();
                        return;

                    }
                    Application.OpenForms["frmTable"].ShowDialog();
                    return;
                }
                MessageBox.Show("Bạn chưa chưa được cấp quyền sử dụng cho tính năng này");
            }
            catch (Exception)
            {


            }
          
        }

        private void mónĂnThứcUốngToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {

                if (checkRole.CHECKROLE(general.groupUserCode, Role.item_read))
                {
                    if (Application.OpenForms["frmItem"] == null)
                    {
                        frmItem area = new frmItem();
                        area.ShowDialog();
                        return;

                    }
                    Application.OpenForms["frmItem"].ShowDialog();
                    return;
                }
                MessageBox.Show("Bạn chưa chưa được cấp quyền sử dụng cho tính năng này");
            }
            catch (Exception)
            {


            }
           
        }

        private void nguyênVậtLiệuToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {

                if (checkRole.CHECKROLE(general.groupUserCode, Role.material_read))
                {
                    if (Application.OpenForms["frmMaterial"] == null)
                    {
                        frmMaterial area = new frmMaterial();
                        area.ShowDialog();
                        return;

                    }
                    Application.OpenForms["frmMaterial"].ShowDialog();
                    return;
                }
                MessageBox.Show("Bạn chưa chưa được cấp quyền sử dụng cho tính năng này");
            }
            catch (Exception)
            {


            }
          
        }

        #endregion

        private void thêmNhânViênMớiToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {

                if (checkRole.CHECKROLE(general.groupUserCode, Role.emp_read))
                {
                    if (Application.OpenForms["frmEmployer"] == null)
                    {
                        frmEmployer area = new frmEmployer();
                        area.ShowDialog();
                        return;

                    }
                    Application.OpenForms["frmEmployer"].ShowDialog();
                }
                MessageBox.Show("Bạn chưa chưa được cấp quyền sử dụng cho tính năng này");
            }
            catch (Exception)
            {


            }
            
        }

        private void cậpNhậtThôngTinNhânViênToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Application.OpenForms["frmEmployer"] == null)
            {
                frmEmployer area = new frmEmployer();
                area.ShowDialog();
                return;

            }
            Application.OpenForms["frmEmployer"].ShowDialog();
        }

        private void xóaNhânViênToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Application.OpenForms["frmEmployer"] == null)
            {
                frmEmployer area = new frmEmployer();
                area.ShowDialog();
                return;

            }
            Application.OpenForms["frmEmployer"].ShowDialog();
        }

        private void panel4_Paint(object sender, PaintEventArgs e)
        {

        }

        private void tạoTàiKhoảnMớiToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {

                if (checkRole.CHECKROLE(general.groupUserCode, Role.user_read))
                {
                    if (Application.OpenForms["frmUserAccount"] == null)
                    {
                        frmUserAccount area = new frmUserAccount();
                        area.ShowDialog();
                        return;
                    }
                    Application.OpenForms["frmUserAccount"].ShowDialog();
                    return;
                }
                MessageBox.Show("Bạn chưa chưa được cấp quyền sử dụng cho tính năng này");
            }
            catch (Exception)
            {


            }

          
        }

        private void xóaTàiKhoảnNgườiDùngToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Application.OpenForms["frmUserAccount"] == null)
            {
                frmUserAccount area = new frmUserAccount();
                area.ShowDialog();
                return;

            }
            Application.OpenForms["frmUserAccount"].ShowDialog();
        }

        private void thiếtLậpMáyInToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (checkRole.CHECKROLE(general.groupUserCode, Role.print_setting))
            {
                if (Application.OpenForms["frmPrintSetting"] == null)
                {
                    frmPrintSetting area = new frmPrintSetting();
                    area.ShowDialog();
                    return;

                }
                Application.OpenForms["frmPrintSetting"].ShowDialog();
                return;
            }
            MessageBox.Show("Bạn chưa chưa được cấp quyền sử dụng cho tính năng này");
        }

        private void thoátToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn có thực sự muốn thoát khỏi ứng dụng ?","Thông báo",MessageBoxButtons.YesNo,MessageBoxIcon.Warning)==DialogResult.Yes)
            {
                Application.Exit();
            }
           
        }

        private void logoutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn có thực sự muốn đăng xuất ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
            {
                
                Application.OpenForms["frmLogin"].Show();
                this.Close();
            }
        }

        private void txttable_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar))
            {
                e.Handled = true;
                return;

            }

            if (((Keys)e.KeyChar == Keys.Enter))
            {
                txtShortcut.Text = "";
                txtShortcut.Focus();
                General.general.TableId = int.Parse(txttable.Text);
            }
        }

        private void txttable_Leave(object sender, EventArgs e)
        {
            if (txttable.Text == "")
            {
                // MessageBox.Show("Số bàn không thể để trống", "Thông báo");

                txttable.Focus();
                return;
            }
            General.general.TableId = int.Parse(txttable.Text);
        }

        private void txtShortcut_KeyDown(object sender, KeyEventArgs e)
        {
            if ((e.KeyCode == Keys.Right))
            {
                gridView3.Focus();
                var result = gridView3.GetFocusedRowCellValue("ITEMNAME");
                txtItemName.Text = result.ToString();

            }
        }

        private void txtShortcut_KeyPress(object sender, KeyPressEventArgs e)
        {
            try
            {
                if (((Keys)e.KeyChar == Keys.Enter))
                {
                    gridView3.Focus();
                    var result = gridView3.GetFocusedRowCellValue("ITEMNAME");
                    txtItemName.Text = result.ToString();
                }
            }
            catch (Exception)
            {

                return;
            }
    
        }

        private void txtShortcut_TextChanged(object sender, EventArgs e)
        {
            gridView3.Columns["SHORTCUT"].FilterInfo =
  new ColumnFilterInfo("[SHORTCUT] LIKE '" + txtShortcut.Text + "%'");
            if (txtShortcut.Text.Trim() == "")
            {
                glkItem.Visible = false;
            }
            else
            {
                glkItem.Visible = true;
            }

        }

        private void txtQuantity_KeyPress(object sender, KeyPressEventArgs e)
        {
            try
            {
                if (((Keys)e.KeyChar == Keys.Enter))
                {
                    frmControl control = new frmControl();

                    var result = control.AddItemToExportForForm(int.Parse(this.txtQuantity.Text));
                    if (result == true)
                    {
                        var button = (SimpleButton)this.panelTable.Controls.Find(general.TableId.ToString(), true)[0];
                        button.Appearance.BackColor = System.Drawing.Color.Wheat;
                        button.Appearance.ForeColor = Color.Black;
                        this.LoadDataGridDetail();
                        return;
                    }
                    if (result == null)
                    {
                    }
                    else
                    {


                        var button1 = (SimpleButton)this.panelTable.Controls.Find(general.TableId.ToString(), true)[0];
                        button1.Appearance.BackColor = System.Drawing.Color.DodgerBlue;

                        this.txtShortcut.SelectAll();
                        this.txtShortcut.Focus();
                        this.LoadDataGridDetail();
                    }
                }
            }
            catch (Exception)
            {

                txtQuantity.SelectAll();
                txtQuantity.Focus();
            }

        }

        private void glkItem_KeyDown(object sender, KeyEventArgs e)
        {
            if ((e.KeyCode == Keys.Left))
            {
                txtShortcut.Focus();
                txtItemName.Text = "";
                glkItem.Visible = false;
            }
        }

        private void glkItem_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (((Keys)e.KeyChar == Keys.Enter))
            {
                glkItem.Visible = false;
                txtQuantity.Focus();
                txtQuantity.Text = "1";
                txtQuantity.SelectAll();
                var result = gridView3.GetFocusedRowCellValue("ITEMID");

                General.general.itemId = int.Parse(result.ToString());

            }
        }

        private void glkItem_Leave(object sender, EventArgs e)
        {
            var result = gridView3.GetFocusedRowCellValue("ITEMID");
            if (result != null)
            {
                General.general.itemId = int.Parse(result.ToString());
            }
        }
        bool flag = false;
        private void frmControl_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {

           
            if (e.KeyData.ToString() == general.NEWTABLE)
            {
                if (flag == false)
                {
                    if (general.TableId > 0)
                    {
                        txttable.Text = general.TableId.ToString();
                        txttable.SelectAll();
                        txttable.Focus();
                        panelExportByForm.Visible = true;
                        txtShortcut.Focus();
                    }
                    flag = true;
                    return;
                }
              
                    panelExportByForm.Visible = false;
                flag = false;
            }

            if (e.KeyData.ToString() == general.SLIPT)
            {
                if (Application.OpenForms["frmSplitTable"] == null)
                {
                    frmSplitTable area = new frmSplitTable();
                    area.ShowDialog();
                    var button2 = (SimpleButton)this.panelTable.Controls.Find(general.TableId.ToString(), true)[0];
                    button2.Appearance.BackColor = System.Drawing.Color.DodgerBlue;
                    this.LoadDataGridDetail();
                    return;
                }
                Application.OpenForms["frmSplitTable"].ShowDialog();
                var button1 = (SimpleButton)this.panelTable.Controls.Find(general.TableId.ToString(), true)[0];
                button1.Appearance.BackColor = System.Drawing.Color.DodgerBlue;
                this.LoadDataGridDetail();
                return;
            }

            if (e.KeyData.ToString() == general.JOIN)
            {
                if (Application.OpenForms["FrmJoinTable"] == null)
                {
                    FrmJoinTable area = new FrmJoinTable();
                    area.ShowDialog();
                    this.LoadDataGridDetail();
                    var button1 = (SimpleButton)this.panelTable.Controls.Find(general.tableIdJoin.ToString(), true)[0];
                    button1.Appearance.BackColor = System.Drawing.Color.Wheat;
                    button1.Appearance.ForeColor = Color.Black;
                    return;
                }
                Application.OpenForms["FrmJoinTable"].ShowDialog();
                this.LoadDataGridDetail();
                var button = (SimpleButton)this.panelTable.Controls.Find(general.tableIdJoin.ToString(), true)[0];
                button.Appearance.BackColor = System.Drawing.Color.Wheat;
                button.Appearance.ForeColor = Color.Black;
                return;
            }

            if (e.KeyData.ToString() == general.PAID)
            {
                try
                {
                    if (gridView2.RowCount > 0)
                    {


                        if (MessageBox.Show("Bạn có muốn in hóa đơn ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {

                            printDocument1.PrinterSettings.PrinterName = general.PrinterBillName;
                            printDocument1.Print();
                        }
                        general.DatePaid = DateTime.Now;
                        expBLL.PAIDBILL(general.EXPORTID, general.DatePaid);
                        var button = (SimpleButton)this.panelTable.Controls.Find(general.TableId.ToString(), true)[0];
                        button.Appearance.BackColor = System.Drawing.Color.Wheat;
                        button.Appearance.ForeColor = Color.Black;
                    }

                }
                catch (Exception)
                {

                    MessageBox.Show("Không tìm thấy máy in vui lòng kiểm tra lại phần cài đặt", "Thông báo");
                    return;
                }

                return;
            }

            if (e.KeyData.ToString() == general.PRINTAGAIN)
            {
                if (Application.OpenForms["frmPrintAgain"] == null)
                {
                    frmPrintAgain area = new frmPrintAgain();
                    area.ShowDialog();
                    return;
                }
                Application.OpenForms["frmPrintAgain"].ShowDialog();

                return;
            }

            if (e.KeyData.ToString() == general.PRINTNOTPAY)
            {
                try
                {
                    if (gridView2.RowCount > 0)
                    {



                        printDocument1.PrinterSettings.PrinterName = general.PrinterBillName;
                        printDocument1.Print();


                    }

                }
                catch (Exception)
                {

                    MessageBox.Show("Không tìm thấy máy in vui lòng kiểm tra lại phần cài đặt", "Thông báo");
                    return;
                }
           
                return;
            }

            if (e.KeyData.ToString() == general.HELP)
            {

                return;
            }

            if (e.KeyData.ToString() == general.REPORT)
            {
                if (Application.OpenForms["frmReport"] == null)
                {
                    frmReport area = new frmReport();
                    area.ShowDialog();

                    return;
                }
                Application.OpenForms["frmReport"].ShowDialog();
                return;
            }

            if (e.KeyData.ToString() == general.CHANGEPASS)
            {
                if (Application.OpenForms["frmChangePassword"] == null)
                {
                    frmChangePassword area = new frmChangePassword();
                    area.ShowDialog();

                    return;
                }
                Application.OpenForms["frmChangePassword"].ShowDialog();
                
            }
            }
            catch (Exception)
            {


            }
        }

        public bool? AddItemToExportForForm(int quantity)
        {
            try
            {
                EXPORTDETAILENT row = (EXPORTDETAILENT)this.gridView2.GetFocusedRow();

                // check table is having guest
                if (this.expBLL.ISTABLEHAVEGUEST(general.TableId) == general.TableId)
                {
                    if (quantity < 0)
                    {
                        if (expBLL.ADDITEMTOTABLE(general.EXPORTID, general.itemId, quantity))
                        {

                            return true;
                        }
                    }
                    this.expBLL.ADDITEMTOTABLE(general.EXPORTID, general.itemId, quantity);

                    return false;
                }
                else
                {
                    if (quantity < 0)
                    {
                        if (expBLL.ADDITEMTOTABLE(general.EXPORTID, general.itemId, quantity))
                        {
                            
                            return true;
                        }
                    }
                    this.expBLL.ADDITEMTOTABLE(this.expBLL.GETNUMBEROFEXPORT(general.TableId, general.empId), general.itemId, quantity);
                    return false;


                }
            }
            catch (Exception)
            {
                return null;
            }
        }

        private void panelExportByForm_Leave(object sender, EventArgs e)
        {
            //panelExportByForm.Visible = false;
        }

        private void btIntam_Click(object sender, EventArgs e)
        {
            try
            {
                if (gridView2.RowCount > 0)
                {


                   
                        printDocument1.PrinterSettings.PrinterName = general.PrinterBillName;
                        printDocument1.Print();
                    
                   
                }

            }
            catch (Exception)
            {

                MessageBox.Show("Không tìm thấy máy in vui lòng kiểm tra lại phần cài đặt", "Thông báo");
                return;
            }
           


        }

        private void chuyểnBànToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (checkRole.CHECKROLE(general.groupUserCode, Role.split_table))
                {

                    if (Application.OpenForms["frmSplitTable"] == null)
                    {
                        frmSplitTable area = new frmSplitTable();
                        area.ShowDialog();
                        var button2 = (SimpleButton)this.panelTable.Controls.Find(general.TableId.ToString(), true)[0];
                        button2.Appearance.BackColor = System.Drawing.Color.DodgerBlue;
                        this.LoadDataGridDetail();
                        return;
                    }
                    Application.OpenForms["frmSplitTable"].ShowDialog();
                    if (general.SuccessFlag)
                    {
                        var button1 = (SimpleButton)this.panelTable.Controls.Find(general.TableId.ToString(), true)[0];
                        button1.Appearance.BackColor = System.Drawing.Color.DodgerBlue;
                        this.LoadDataGridDetail();
                    }
                    
                    return;
                }
                MessageBox.Show("Bạn chưa chưa được cấp quyền sử dụng cho tính năng này");
            }
            catch (Exception)
            {
                
                
            }
            

        }

        private void ghépBànToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {

                if (checkRole.CHECKROLE(general.groupUserCode, Role.join_table))
                {
                    if (Application.OpenForms["FrmJoinTable"] == null)
                    {
                        FrmJoinTable area = new FrmJoinTable();
                        area.ShowDialog();
                        this.LoadDataGridDetail();
                        var button1 = (SimpleButton)this.panelTable.Controls.Find(general.tableIdJoin.ToString(), true)[0];
                        button1.Appearance.BackColor = System.Drawing.Color.Wheat;
                        button1.Appearance.ForeColor = Color.Black;
                        return;
                    }
                    Application.OpenForms["FrmJoinTable"].ShowDialog();
                    this.LoadDataGridDetail();
                    var button = (SimpleButton)this.panelTable.Controls.Find(general.tableIdJoin.ToString(), true)[0];
                    button.Appearance.BackColor = System.Drawing.Color.Wheat;
                    button.Appearance.ForeColor = Color.Black;
                    return;
                }
                MessageBox.Show("Bạn chưa chưa được cấp quyền sử dụng cho tính năng này");
            }
            catch (Exception)
            {


            }
           
          
        }

        private void báoCáoTổngHợpToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {

                if (checkRole.CHECKROLE(general.groupUserCode, Role.report))
                {
                    if (Application.OpenForms["frmReport"] == null)
                    {
                        frmReport area = new frmReport();
                        area.ShowDialog();

                        return;
                    }
                    Application.OpenForms["frmReport"].ShowDialog();
                    return;
                }
                MessageBox.Show("Bạn chưa chưa được cấp quyền sử dụng cho tính năng này");
            }
            catch (Exception)
            {


            }

           
        }

        private void cấpQuyềnSửDụngToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {

                if (checkRole.CHECKROLE(general.groupUserCode, Role.permission))
                {
                    if (Application.OpenForms["frmPermit"] == null)
                    {
                        frmPermit area = new frmPermit();
                        area.ShowDialog();

                        return;
                    }
                    Application.OpenForms["frmPermit"].ShowDialog();
                    return;
                }
                MessageBox.Show("Bạn chưa chưa được cấp quyền sử dụng cho tính năng này");
            }
            catch (Exception)
            {


            }

           
        }

        private void thayĐổiMậtKhẩuToolStripMenuItem_Click(object sender, EventArgs e)
        {

            try
            {

                if (checkRole.CHECKROLE(general.groupUserCode, Role.change_pass))
                {
                    if (Application.OpenForms["frmChangePassword"] == null)
                    {
                        frmChangePassword area = new frmChangePassword();
                        area.ShowDialog();

                        return;
                    }
                    Application.OpenForms["frmChangePassword"].ShowDialog();
                    return;
                }
                MessageBox.Show("Bạn chưa chưa được cấp quyền sử dụng cho tính năng này");
            }
            catch (Exception)
            {


            }
           
        }

        private void đặtLạiMậtKhẩuToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {

                if (checkRole.CHECKROLE(general.groupUserCode, Role.user_read))
                {
                    if (Application.OpenForms["frmUserAccount"] == null)
                    {
                        frmUserAccount area = new frmUserAccount();
                        area.ShowDialog();
                        return;
                    }
                    Application.OpenForms["frmUserAccount"].ShowDialog();
                    return;
                }
                MessageBox.Show("Bạn chưa chưa được cấp quyền sử dụng cho tính năng này");
            }
            catch (Exception)
            {


            }
            
        }

        private void inLạiHóaĐơnToolStripMenuItem_Click(object sender, EventArgs e)
        {

            try
            {

                if (checkRole.CHECKROLE(general.groupUserCode, Role.print_flag))
                {
                    if (Application.OpenForms["frmPrintAgain"] == null)
                    {
                        frmPrintAgain area = new frmPrintAgain();
                        area.ShowDialog();
                        return;
                    }
                    Application.OpenForms["frmPrintAgain"].ShowDialog();
                    return;
                }
                MessageBox.Show("Bạn chưa chưa được cấp quyền sử dụng cho tính năng này");
            }
            catch (Exception)
            {


            }
           
        }

        private void thiếtKếHóaĐơnTínhTiềnToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (checkRole.CHECKROLE(general.groupUserCode, Role.bill_setting))
            {
                if (Application.OpenForms["frmBillSetting"] == null)
                {
                    frmBillSetting area = new frmBillSetting();
                    area.ShowDialog();
                    return;
                }
                Application.OpenForms["frmBillSetting"].ShowDialog();
                return;
            }
            MessageBox.Show("Bạn chưa chưa được cấp quyền sử dụng cho tính năng này");


          
        }

        private void danhSáchQuyềnToolStripMenuItem_Click(object sender, EventArgs e)
        {

            if (Application.OpenForms["frmRole"] == null)
            {
                frmRole area = new frmRole();
                area.ShowDialog();
                return;
            }
            Application.OpenForms["frmRole"].ShowDialog();
        }

        private void thiếtLậpPhímTắtChứcNăngToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (checkRole.CHECKROLE(general.groupUserCode, Role.shortcut_setting))
            {
                if (Application.OpenForms["frmShortcutSetting"] == null)
                {
                    frmShortcutSetting area = new frmShortcutSetting();
                    area.ShowDialog();
                    return;
                }
                Application.OpenForms["frmShortcutSetting"].ShowDialog();
                return;
            }
            MessageBox.Show("Bạn chưa chưa được cấp quyền sử dụng cho tính năng này");

            
        }

        private void lậpHóaĐơnBánHàngToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void toolStripMenuItem3_Click(object sender, EventArgs e)
        {
            if (checkRole.CHECKROLE(general.groupUserCode, Role.shortcut_setting))
            {
                if (Application.OpenForms["frmBackup"] == null)
                {
                    frmBackup area = new frmBackup();
                    area.ShowDialog();
                    return;
                }
                Application.OpenForms["frmBackup"].ShowDialog();
                return;
            }
            MessageBox.Show("Bạn chưa chưa được cấp quyền sử dụng cho tính năng này");
        }

        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            if (checkRole.CHECKROLE(general.groupUserCode, Role.shortcut_setting))
            {
                if (Application.OpenForms["frmServerConfig"] == null)
                {
                    frmServerConfig area = new frmServerConfig();
                    area.ShowDialog();
                    return;
                }
                Application.OpenForms["frmServerConfig"].ShowDialog();
                return;
            }
            MessageBox.Show("Bạn chưa chưa được cấp quyền sử dụng cho tính năng này");
        }

        private void thôngTinVềPhầnMềmToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Application.OpenForms["frmInfomation"] == null)
            {
                frmInfomation area = new frmInfomation();
                area.ShowDialog();
                return;
            }
            Application.OpenForms["frmInfomation"].ShowDialog();
        }
       
    }
}
